import java.util.Arrays;

public class selectedSort {
    public static  void sort(int[] nums){
        if(nums.length == 0 || nums == null){
            return;
        }
        int minIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if(nums[j] < nums[minIndex]){
                    minIndex = j;
                }
            }
            swap(nums,minIndex,i);
        }
    }

    private static void swap(int[] nums, int minIndex, int i){
        int tmp = nums[minIndex];
        nums[minIndex] = nums[i];
        nums[i] = tmp;
    }
    public static void main(String[] str){
        int[] nums = {22,31,2,1,5,10};
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
